﻿package com.wandian.view.components.ui
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.UserInfoProxy;
	import com.wandian.model.vo.*;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZButtonFour;
	import com.wandian.util.CLZSlideTwo;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.TextControl;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class SitPlayerPanel extends Object
	{
		private var _mcOperate:Sprite;
		private var _timer:Timer;
		private var _facade:ApplicationFacade;
		private var _playerVo:PlayerVo;
		private var _global:GameData;
		private var _inRoomData:InRoomPlayerDataProxy;
		private var _userInfo:UserInfoProxy;
		private var _filter:GlowFilterManage;

		public function SitPlayerPanel(mcOperate:Sprite)
		{
			this._timer=new Timer(1000, 1);
			this._facade=ApplicationFacade.getInstance();
			this._global=GameData.getInstance();
			this._filter=GlowFilterManage.getInstance();
			this._inRoomData=this._facade.retrieveProxy(InRoomPlayerDataProxy.NAME) as InRoomPlayerDataProxy;
			this._userInfo=this._facade.retrieveProxy(UserInfoProxy.NAME) as UserInfoProxy;
			this._mcOperate=mcOperate;
			this._mcOperate.addEventListener(MouseEvent.ROLL_OVER, this.rollOverHandler);
			this._mcOperate.addEventListener(MouseEvent.ROLL_OUT, this.rollOutHandler);
			this._timer.addEventListener(TimerEvent.TIMER_COMPLETE, this.timerCompleteHandler);
			CLZButton.setButton(this._mcOperate["info_btn"], GameData.tip["INFO_BTN"]);
			CLZButton.setButton(this._mcOperate["giveGift_btn"], GameData.tip["GIVEGIFT_BTN"]);
			CLZButton.setButton(this._mcOperate["giveChip_btn"], GameData.tip["GIVECHIP_BTN"]);
			CLZButton.setButton(this._mcOperate["addFriend_btn"], "", {tip: GameData.tip["ADD_FRIEND_NAME"], time: 10});
			CLZButton.setButton(this._mcOperate["tick_btn"], "", {tip: GameData.tip["VIP_LIST_FLAG_9"], time: 10});
			CLZButton.setButton(this._mcOperate["banSpeak_btn"], "", {tip: GameData.tip["VIP_LIST_FLAG_8"], time: 10});
			CLZButton.setButton(this._mcOperate["speak_btn"], "", {tip: GameData.tip["SPEEK_CARD_NAME"], time: 10});
			CLZButton.setButton(this._mcOperate["flower_btn"], "", {tip: GameData.tip["FLOWER_NAME"], time: 10});
			CLZButton.setButton(this._mcOperate["kiss_btn"], "", {tip: GameData.tip["KISS_NAME"], time: 10});
			CLZButton.setButton(this._mcOperate["egg_btn"], "", {tip: GameData.tip["EGG_NAME"], time: 10});
			CLZButton.setButton(this._mcOperate["handshake_btn"], "", {tip: GameData.tip["HANDSHAKE_NAME"], time: 10});
			this._mcOperate["addFriend_btn"].addEventListener(MouseEvent.CLICK, this.requestFriendHandler);
			this._mcOperate["tick_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["banSpeak_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["speak_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["flower_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["kiss_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["egg_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["handshake_btn"].addEventListener(MouseEvent.CLICK, this.requestBtnHandler);
			this._mcOperate["info_btn"].addEventListener(MouseEvent.CLICK, this.onInfoHandler);
			this._mcOperate["giveGift_btn"].addEventListener(MouseEvent.CLICK, this.onGiveGiftHandler);
			this._mcOperate["giveChip_btn"].addEventListener(MouseEvent.CLICK, this.onGiveChipHandler);
			TextControl.initAddSubTxt(this._mcOperate["giveChipTxt_mc"], this._mcOperate["giveChipTxt_mc"]["input_txt"], this._mcOperate["giveChipTxt_mc"]["add_btn"], this._mcOperate["giveChipTxt_mc"]["sub_btn"], 50, 500, 50);
			return;
		} 

		private function requestBtnHandler(event:MouseEvent):void
		{
			var _loc_3:String=null;
			var _loc_4:Object=null;
			var _loc_2:*=event.target.name;
			if (_loc_2 != "tick_btn")
			{
			}
			if (_loc_2 == "banSpeak_btn")
			{
				if (this._global.userInfo.userVo.vip < this._playerVo.vip)
				{
					_loc_3=GameData.tip["NOT_VIP_TIP_BANK"];
					_loc_4={okNoticeName: CLZNoticeName.ON_PAY_VIP, tip: _loc_3, tipTitle: GameData.tip["SYSTEM_TIP"], isCancel: true, okTip: "ON_PAY_VIP_NAME", cancelTip: "I_KNOW", isSendClose: false};
					this._facade.sendNotification(CLZNoticeName.SHOW_WINDOWS_TIP, _loc_4);
					this.closeThis();
					return;
				}
			}
			switch (event.target.name)
			{
				case "tick_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_KICK_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				case "banSpeak_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_BANSPEAK_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				case "speak_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_SPEAK_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				case "flower_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_FLOWER_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				case "kiss_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_KISS_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				case "egg_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_EGG_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				case "handshake_btn":
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_USE_SELECTED_TIP, {pcate: GameData.PROP_PCATE_ID_1, pframe: GameData.PROP_HANDSHAKE_PFRAME_ID, playerVo: this._playerVo});
					break;
				}
				default:
				{
					break;
				}
			}
			this.closeThis();
			return;
		} 

		private function requestFriendHandler(event:MouseEvent):void
		{
			var _loc_2:Object={okNoticeName: CLZNoticeName.FRIEND_TO_REQUEST_REQ, tip: GameData.replaceStrValue(GameData.tip["FRIEND_REQUEST_FROM"], "NAME", this._playerVo.name), tipTitle: GameData.tip["SYSTEM_TIP"], isCancel: true, data: this._playerVo};
			this._facade.sendNotification(CLZNoticeName.SHOW_WINDOWS_TIP, _loc_2);
			this.closeThis();
			return;
		} 

		private function onInfoHandler(event:MouseEvent):void
		{
			this._facade.sendNotification(CLZNoticeName.SHOW_ACCOUNT, this._playerVo);
			this.closeThis();
			return;
		} 

		private function onGiveGiftHandler(event:MouseEvent):void
		{
			this._facade.sendNotification(CLZNoticeName.SHOW_SHOPING_GIFT, this._playerVo);
			this.closeThis();
			return;
		} 

		private function onGiveChipHandler(event:MouseEvent):void
		{
			var play:PlayerVo=this._inRoomData.getInRoomPlayer(this._global.userInfo.userVo.userid);
			var giveMoney:Number=Number(this._mcOperate["giveChipTxt_mc"]["input_txt"].text);
			if (GameData._nCurSeatId == this._global.seatId)
			{
			}
			if (this._global.seatId == 0)
			{
			}
			if (this._global.seatId != 0)
			{
			}
			if (play.stake < giveMoney + GameData._objRoom.minBlind * 2)
			{
				this._facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: GameData.tip["SEND_BAN"]});
				return;
			}
			this._facade.sendNotification(CLZNoticeName.GIVE_CHIP_REQ, {fromMid: this._global.userInfo.userVo.userid, toMid: this._playerVo.userid, chip: giveMoney});
			this.closeThis();
			return;
		} 

		private function onIndexHandler(event:MouseEvent):void
		{
			this._facade.sendNotification(CLZNoticeName.INDEX_BTN, this._playerVo);
			this.closeThis();
			return;
		} 

		private function rollOverHandler(event:MouseEvent):void
		{
			this.removeTimer();
			return;
		} 

		private function rollOutHandler(event:MouseEvent):void
		{
			this.closeThis();
			return;
		} 

		public function set player(param1:PlayerVo):void
		{
			var _loc_2:Array=null;
			var _loc_3:int=0;
			var _loc_4:int=0;
			var _loc_5:FriendVo=null;
			this._playerVo=param1;
			CLZButton.enabled(this._mcOperate["addFriend_btn"]);
			if (this._global.userInfo.userVo.userid != param1.userid)
			{
				if (GameData._nCurSeatId == this._global.seatId)
				{
				}
			}
			if (this._global.seatId == 0)
			{
			}
			if (this._global.judgeMoneyType(GameData._objRoom.type) != 0)
			{
			}
			if (this._global.seatId != 0)
			{
			}
			if (param1.isSend)
			{
				CLZButton.enabled(this._mcOperate["giveChip_btn"], false);
				CLZButton.enabled(this._mcOperate["giveChipTxt_mc"], false);
			}
			else
			{
				CLZButton.enabled(this._mcOperate["giveChip_btn"]);
				CLZButton.enabled(this._mcOperate["giveChipTxt_mc"]);
			}
			if (param1.userid == this._global.userInfo.userVo.userid)
			{
				CLZButton.enabled(this._mcOperate["addFriend_btn"], false);
				CLZButton.enabled(this._mcOperate["tick_btn"], false);
				CLZButton.enabled(this._mcOperate["flower_btn"], false);
				CLZButton.enabled(this._mcOperate["kiss_btn"], false);
				CLZButton.enabled(this._mcOperate["egg_btn"], false);
				CLZButton.enabled(this._mcOperate["handshake_btn"], false);
				CLZButton.enabled(this._mcOperate["banSpeak_btn"], false);
			}
			else
			{
				if (this._global.seatId == 0)
				{
					CLZButton.enabled(this._mcOperate["giveGift_btn"], false);
					CLZButton.enabled(this._mcOperate["flower_btn"], false);
					CLZButton.enabled(this._mcOperate["kiss_btn"], false);
					CLZButton.enabled(this._mcOperate["egg_btn"], false);
					CLZButton.enabled(this._mcOperate["handshake_btn"], false);
				}
				else
				{
					CLZButton.enabled(this._mcOperate["giveGift_btn"]);
					CLZButton.enabled(this._mcOperate["flower_btn"]);
					CLZButton.enabled(this._mcOperate["kiss_btn"]);
					CLZButton.enabled(this._mcOperate["egg_btn"]);
					CLZButton.enabled(this._mcOperate["handshake_btn"]);
				}
				CLZButton.enabled(this._mcOperate["tick_btn"]);
				if (this.player.banSpeak == -1)
				{
					CLZButton.enabled(this._mcOperate["banSpeak_btn"]);
				}
				else
				{
					CLZButton.enabled(this._mcOperate["banSpeak_btn"], false);
				}
				_loc_2=this._userInfo.arrFriend;
				_loc_3=_loc_2.length;
				_loc_4=0;
				while (_loc_4 < _loc_3)
				{

					_loc_5=_loc_2[_loc_4];
					if (_loc_5 != null)
					{
					}
					if (_loc_5.userid == param1.userid)
					{
						CLZButton.enabled(this._mcOperate["addFriend_btn"], false);
						break;
					}
					_loc_4=_loc_4 + 1;
				}
			}
			if (this.player.banSpeak == 1)
			{
				CLZButton.enabled(this._mcOperate["speak_btn"]);
			}
			else
			{
				CLZButton.enabled(this._mcOperate["speak_btn"], false);
			}
			this.startTimer();
			return;
		} 

		public function get player():PlayerVo
		{
			return this._playerVo;
		} 

		private function timerCompleteHandler(event:TimerEvent):void
		{
			if (!this._mcOperate.hitTestPoint(Texas.I._mcTipView.stage.mouseX, Texas.I._mcTipView.stage.mouseY))
			{
				this.closeThis();
			}
			return;
		} 

		private function startTimer():void
		{
			this._timer.reset();
			this._timer.start();
			return;
		} 

		private function removeTimer():void
		{
			this._timer.reset();
			return;
		} 

		private function closeThis():void
		{
			this.removeTimer();
			this._facade.sendNotification(CLZNoticeName.CLOSE_BTN_PLAYER_OPERATE);
			return;
		} 

	}
}
